package com.wzd.shoppingService.model.dao;

import com.github.pagehelper.PageHelper;
import com.wzd.hp.model.entity.SysRolePermission;
import com.wzd.hp.model.mapper.SysRolePermissionMapper;
import com.wzd.param.PageParam;
import com.wzd.utils.MathUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * TODO: 角色权限表Dao
 *
 * @author WeiZiDong
 */
@Component
public class SysRolePermissionDao {
    @Resource
    private SysRolePermissionMapper mapper;

    /**
     * 根据ID获取
     */
    public SysRolePermission getById(String id) {
        return mapper.selectByPrimaryKey(id);
    }

    /**
     * 检查是否存在
     */
    public boolean exists(String id) {
        return mapper.existsWithPrimaryKey(id);
    }

    /**
     * 更新用户
     */
    public void update(SysRolePermission sysRolePermission) {
        sysRolePermission.setUpdateTime(new Date());
        mapper.updateByPrimaryKeySelective(sysRolePermission);
    }

    /**
     * 创建用户
     */
    public void create(SysRolePermission sysRolePermission) {
        sysRolePermission.setId(MathUtil.getUUID());
        sysRolePermission.setCreateTime(new Date());
        mapper.insertSelective(sysRolePermission);
    }

    /**
     * 分页查询
     */
    public List<SysRolePermission> find(PageParam param) {
        if (param.getPageSize() != null && param.getPageSize() > 0) {
            PageHelper.startPage(param.getPage(), param.getPageSize());
        }
        return mapper.selectAll();
    }

    /**
     * 删除
     */
    public void del(String id) {
        mapper.deleteByPrimaryKey(id);
    }
}
